<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2023/5/8
 * Time: 10:56
 */

namespace app\admin\controller;
use app\common\controller\Backend;
use think\Db;
class Automatic extends Backend
{
    /**
     * Car模型对象
     * @var \app\admin\model\Car
     */

    public function _initialize()
    {
        parent::_initialize();
    }

    //自动生成学生信息
    public function student()
    {
        $time = date('Y-m-d');
        $strtime = time();
        $list = Db::name('student_information')->field("id,class_room_id,RC_NUM,circuit_id,point,name")->select();

        if($list)
        {
            $data = [];
            foreach ($list as $k=>$v)
            {
                $arr['student_id'] = $v['id'];
                $arr['class_room_id'] = $v['class_room_id'];
                $arr['RC_NUM'] = $v['RC_NUM'];
                $arr['time'] = $time;
                $arr['createtime'] = $strtime;
                $arr['updatetime'] = $strtime;
                $arr['circuit_id'] = $v['circuit_id'];
                $arr['point'] = $v['point'];
                $arr['name'] = $v['name'];

                $data[] = $arr;
            }

            $res = Db::name('automatic_student')->insertAll($data);
            if($res)
            {
                echo '生成成功';
            }
            else
            {
                echo '生成失败';
            }
        }

    }

    //自动生成老师到岗情况
    public function work()
    {
        $role = [
            2=>'班主任',
            3=>'协管老师',
            4=>'值日行政人员',
            5=>'校车安全管理人员',
        ];
        //1=家长,2=班主任,3=协管老师,4=值日行政人员,5=校车安全管理人员
        //$list = Db::name('admin')->field('id,nickname,role')->where(['role'=>['in',[2,3,4,5]]])->select();
        $where = [];
        //$where['time'] = date('Y-m-d');
        $list = Db::name('work')->where($where)->select();

        if($list)
        {
            $data = [];
            $time = time();
            foreach ($list as $k=>$v)
            {
                $arr = [];
                $arr['name'] = $v['name'];
                $arr['position'] = $v['position'];
                $arr['time'] = date('Y-m-d');
                $arr['createtime'] = $time;
                $arr['updatetime'] = $time;
                $data[] = $arr;
            }

            $res = Db::name('work')->insertAll($data);
            if($res)
            {
                echo '自动生成成功';exit;
            }
            else
            {
                echo '自动生成失败';exit;
            }
        }
        else
        {
            echo '暂无数据';exit;
        }
    }

    public function test()
    {

            $GPS_LNG = 120.56210043149815;
            $GPS_LAT =30.0215557975932;
        for ($i=1;$i<100;$i++)
        {
            $GPS_LNG=$GPS_LNG+0.0004;
            echo $GPS_LNG;exit;
            $data = [];
            $data['IMEI'] = '861714055270312';
            $data['CSQ'] = '31';
            $data['GPS_LNG'] = $GPS_LNG;
            $data['GPS_LAT'] = $GPS_LAT;
            $data['SPEED'] = 18;
            $data['SYS_VER'] = '1.0.0';
            $data['TEMP'] = '31.6';
            $data['HUM'] = '26.8';
            $data['INIT'] = 1;
            $data['TIME'] = 1682488253;
            $data['DTIME'] = '2023-04-26';
            $res = Db::name('car_zheb578')->insert();
        }
    }
}